package com.longge;

import java.util.Arrays;

/**
 * @program: my-code
 * @description:
 * @author: longge
 * @create: 2021-05-23 23:32
 */
public class Selection {

    public void sort(int[] arr) {
        for (int i = 0; i < arr.length-1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[minIndex] > arr[j]) {
                    minIndex = j;
                }
            }
            if (minIndex != i) {
                int temp = arr[i];
                arr[i] = arr[minIndex];
                arr[minIndex] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {2, 3, 5, 8, 7, 9, 8, 8, 7, 2, 4, 5};
        new Selection().sort(arr);
        System.out.println(Arrays.toString(arr));
    }

}
